package com.jane.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jane.bean.CategoryBean;
import com.jane.gzzb.R;
import com.jane.utils.Utils;

import java.util.ArrayList;

/**
 * Created by Jane on 2016/11/14.
 */

public class CategoryAdapter extends BaseAdapter{
    private ArrayList<CategoryBean.DataListBean> list;
    private LayoutInflater layoutInflater;
    public CategoryAdapter(ArrayList<CategoryBean.DataListBean> list, Context context) {
        this.list = list;
        layoutInflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView=layoutInflater.inflate(R.layout.item_view_category,null);
            vh=new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }
        Utils.loadImage(vh.iv,list.get(position).getImgurl());
        vh.tv1.setText(list.get(position).getName());
        vh.tv2.setText(list.get(position).getLivenum()+"个直播");

        return convertView;
    }
    static class ViewHolder{
        ImageView iv;
        TextView tv1,tv2;

        public ViewHolder(View view) {
            iv= (ImageView) view.findViewById(R.id.iv_item_view_category);
            tv1= (TextView) view.findViewById(R.id.tv1_item_view_category);
            tv2= (TextView) view.findViewById(R.id.tv2_item_view_category);
        }
    }
}
